package asia.doing.controller.admin;

import asia.doing.common.Result;
import asia.doing.entity.Activity;
import asia.doing.service.admin.ManageActivityService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController(value = "manageActivityController")
@RequestMapping("/manage/activity")
public class ManageActivityController {
    @Resource
    private ManageActivityService manageActivityService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody Activity activity) {
        manageActivityService.add(activity);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Long id) {
        manageActivityService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Long> ids) {
        manageActivityService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody Activity activity) {
        manageActivityService.updateById(activity);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Long id) {
        Activity activity = manageActivityService.selectById(id);
        return Result.success(activity);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(Activity activity) {
        List<Activity> list = manageActivityService.selectAll(activity);
        return Result.success(list);
    }
    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(Activity activity,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Activity> page = manageActivityService.selectPage(activity, pageNum, pageSize);
        return Result.success(page);
    }

    /**
     * 热门活动
     */
    @GetMapping("/selectTop")
    public Result selectTop() {
        List<Activity> list = manageActivityService.selectTop();
        return Result.success(list);
    }

    @PutMapping("/updateReadCount/{activityId}")
    public Result updateReadCount(@PathVariable Long activityId) {
        manageActivityService.updateReadCount(activityId);
        return Result.success();
    }


    /**
     * 查询用户报名的活动列表
     */
    @GetMapping("/selectUser")
    public Result selectUser(Activity activity,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Activity> page = manageActivityService.selectUser(activity, pageNum, pageSize);
        return Result.success(page);
    }


    /* 用户个人信息开发接口开始 */
    /**
     * 查询用户点赞的活动列表
     */
    @GetMapping("/selectLike")
    public Result selectLike(Activity activity,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Activity> page = manageActivityService.selectLike(activity, pageNum, pageSize);
        return Result.success(page);
    }

    /**
     * 查询用户收藏的活动列表
     */
    @GetMapping("/selectCollect")
    public Result selectCollect(Activity activity,
                                @RequestParam(defaultValue = "1") Integer pageNum,
                                @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Activity> page = manageActivityService.selectCollect(activity, pageNum, pageSize);
        return Result.success(page);
    }

    /**
     * 查询用户评论的活动列表
     */
    @GetMapping("/selectComment")
    public Result selectComment(Activity activity,
                                @RequestParam(defaultValue = "1") Integer pageNum,
                                @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Activity> page = manageActivityService.selectComment(activity, pageNum, pageSize);
        return Result.success(page);
    }
    /* 用户个人信息开发接口结束 */

}
